<template>
  <div>
    <div class="top">
      <el-button size="mini" type="primary" plain @click="Button_on_AddOrder()">新增借用单</el-button>
      <el-button
        size="mini"
        type="primary"
        :disabled="buttons_canbeused.delete"
        plain
        @click="Button_on_DeleteOrder()"
      >删除借用单</el-button>
      <el-button
        size="mini"
        type="primary"
        :disabled="buttons_canbeused.confirm"
        plain
        @click="Button_on_ConfirmOrder()"
      >审核</el-button>
      <el-button
        size="mini"
        type="primary"
        :disabled="buttons_canbeused.disconfirm"
        plain
        @click="Button_on_DisConfirmOrder()"
      >取消审核</el-button>
      <el-button
        size="mini"
        type="primary"
        :disabled="buttons_canbeused.generate"
        plain
        @click="Button_on_Generate()"
      >生成仓库借出单</el-button>
      <div class="top-check">
        <el-form :inline="true" :model="checkForm" size="mini">
          <el-form-item label="借用单编码">
            <el-input v-model="checkForm.ref"></el-input>
          </el-form-item>
          
          <el-form-item label="状态">
            <el-select v-model="checkForm.statu">
              <el-option label="全部" value></el-option>
              <el-option label="待审核" value="待审核"></el-option>
              <el-option label="已审核" value="已审核"></el-option>
              <el-option label="待借用" value="待借用"></el-option>
              <el-option label="已借用" value="已借用"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="借用日期">
           <el-date-picker
            type="date"
            placeholder="选择日期"
            v-model="checkForm.date"
            value-format="yyyy-MM-dd"
            style="width: 100%;"
          ></el-date-picker>
          </el-form-item>
          
          <el-form-item label="机构组织名">
            <el-input v-model="checkForm.orangename"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="CheckSubmit">查询</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="clear_find">清空查询条件</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <div>
      <el-table
        :data="App_Borrow_List.list"
        @row-click="Select_BorrowList_Row"
        border
        :stripe="true"
        :header-cell-style="{background:'#e3e5e9',color:'#606266'}"
        :row-style="{height:'5px'}"
        :cell-style="{padding:'5px 0'}"
        tooltip-effect="light"
        highlight-current-row
        style="width: 100%;"
        height="400"
      >
        <el-table-column prop="statu" label="状态" width="150"></el-table-column>
        <el-table-column prop="ref" label="编号" width="150"></el-table-column>
        <el-table-column prop="date" label="借用日期" width="150"></el-table-column>
        <el-table-column prop="orangename" label="机构组织" width="150"></el-table-column>
        <el-table-column prop="borrower" label="借用人" width="150"></el-table-column>
        <el-table-column prop="storename" label="预借仓库" width="150"></el-table-column>
        <el-table-column prop="bizName" label="业务员" width="150"></el-table-column>
        <el-table-column prop="memo" label="备注" width="150"></el-table-column>
      </el-table>
    </div>
    <div class="diver"></div>
    <div>
      <div class="detail">
        <el-tabs type="border-card">
          <el-tab-pane>
            <span slot="label">
              <i class="el-icon-s-order"></i>
              单号:{{DetailContentTitle.ref}} 机构组织:{{DetailContentTitle.orangename}} 借用人:{{DetailContentTitle.borrower}}
            </span>
            <div>
              <el-table
                border
                :data="App_DetailBorrow_List.list"
                size="mini"
                :row-style="{height:'5px'}"
                :cell-style="{padding:'5px 0'}"
              >
                <el-table-column  label="序号" width="50">
                  <template slot-scope="scope">
                    <span>{{scope.$index + 1}}</span>
                  </template>
                </el-table-column>
                <el-table-column  label="商品编码" width="250" prop="code"></el-table-column>
                <el-table-column label="商品名称" prop="name" width="200"></el-table-column>
                <el-table-column show-overflow-tooltip prop="spec" label="规格型号" width="250"></el-table-column>
                <el-table-column show-overflow-tooltip prop="count" label="借用数量" width="95"></el-table-column>
                <el-table-column show-overflow-tooltip label="单位" prop="unitname" width="125"></el-table-column>
                <el-table-column prop="memo" show-overflow-tooltip label="备注" width="410"></el-table-column>
              </el-table>
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>
    </div>
    <DialogOfAdd
      v-if="dialog.add_order"
      @dialog-close="dialog.add_order = false"
      @refresh="Refresh_Borrow_List"
      :form="App_Borrow_List.Select_Row"
    ></DialogOfAdd>
    <DialogOfDelete
      v-if="dialog.delete_order"
      @dialog-close="dialog.delete_order = false"
      @refresh="Refresh_Borrow_List"
      :form="App_Borrow_List.Select_Row"
    ></DialogOfDelete>
    <DialogOfConfirm
      v-if="dialog.confirm_order"
      @dialog-close="dialog.confirm_order = false"
      @refresh="Refresh_Borrow_List"
      :form="App_Borrow_List.Select_Row"
    ></DialogOfConfirm>
    <DialogOfDisconfirm
      v-if="dialog.disconfirm_order"
      @dialog-close="dialog.disconfirm_order = false"
      @refresh="Refresh_Borrow_List"
      :form="App_Borrow_List.Select_Row"
    ></DialogOfDisconfirm>
    <DialogOfGenerate
      v-if="dialog.generate"
      @dialog-close="dialog.generate = false"
      @refresh="Refresh_Borrow_List"
      :form="App_Borrow_List.Select_Row"
    ></DialogOfGenerate>
  </div>
</template>

<script>
import DialogOfAdd from "./dialog/add";
import DialogOfDelete from "./dialog/delete";
import DialogOfConfirm from "./dialog/confirm";
import DialogOfDisconfirm from "./dialog/disconfirm";
import DialogOfGenerate from "./dialog/generate";
export default {
  components: {
    DialogOfAdd,
    DialogOfDelete,
    DialogOfConfirm,
    DialogOfDisconfirm,
    DialogOfGenerate
  },
  data() {
    return {
      checkForm: {},
      dialog: {
        add_order: false,
        delete_order: false,
        confirm_order: false,
        disconfirm_order: false,
        generate: false
      },
      buttons_canbeused: {
        delete: true,
        confirm: true,
        disconfirm: true,
        generate: true
      },
      DetailContentTitle: {
        ref: "无",
        orangename: "无"
      },
      App_Borrow_List: {
        list: [],
        Select_Row: {}
      },
      App_DetailBorrow_List: {
        list: [],
        Select_Row: {}
      }
    };
  },
  created() {
    this.Refresh_Borrow_List();
    this.Refresh_DetailBorrow_List(1);
  },
  methods: {
    newMethod() {},
    clear_find(){
      this.checkForm={}
    },
     CheckSubmit() {
       this.$http.post("borrow/search",this.checkForm).then(response =>{
       this.App_Borrow_List.list = response.data
      })
    },
    Refresh_Borrow_List() {
      this.$http.get("borrow/list").then(response => {
        this.App_Borrow_List.list = response.data;
      });
    },
    Refresh_DetailBorrow_List(id) {
      this.$http
        .post("BorrowDetailDetail/somelist", { borrowref: id })
        .then(response => {
          this.App_DetailBorrow_List.list = response.data;
        });
    },
    Select_BorrowList_Row(Row) {
      window.console.log("select_row", Row);

      this.DetailContentTitle.ref = Row.ref;
      this.DetailContentTitle.orangename = Row.orangename;
      this.DetailContentTitle.borrower = Row.borrower;
      this.Refresh_DetailBorrow_List(Row.id);
      this.App_Borrow_List.Select_Row = JSON.parse(JSON.stringify(Row));
      if (Row.statu == "待审核") {
        this.buttons_canbeused.delete = false;
        this.buttons_canbeused.confirm = false;
        this.buttons_canbeused.disconfirm = true;
        this.buttons_canbeused.generate = true;
      }
      if (Row.statu == "已审核") {
        this.buttons_canbeused.delete = true;
        this.buttons_canbeused.confirm = true;
        this.buttons_canbeused.disconfirm = false;
        this.buttons_canbeused.generate = false;
      }
      if (Row.statu == "申请中") {
        this.buttons_canbeused.delete = true;
        this.buttons_canbeused.confirm = true;
        this.buttons_canbeused.disconfirm = true;
        this.buttons_canbeused.generate = true;
      }
      if (Row.statu == "已借用" || Row.statu == "待借用") {
        this.buttons_canbeused.delete = true;
        this.buttons_canbeused.confirm = true;
        this.buttons_canbeused.disconfirm = true;
        this.buttons_canbeused.generate = true;
      }
    },
    Button_on_AddOrder() {
      this.dialog.add_order = true;
    },
    Button_on_DeleteOrder() {
      this.dialog.delete_order = true;
    },
    Button_on_ConfirmOrder() {
      this.dialog.confirm_order = true;
    },
    Button_on_DisConfirmOrder() {
      this.dialog.disconfirm_order = true;
    },
    Button_on_Generate() {
      this.dialog.generate = true;
    }
  }
};
</script>

<style>
</style>